﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Xamarin.Forms;

namespace SharedMobilePlatform
{
	public class HistoryPage : ContentPage
	{
	    private Label history;
        
        public HistoryPage()
        {
            Title = "Historia";
            history = new Label { Text = "", FontSize = Device.GetNamedSize(NamedSize.Medium, typeof(Label)) };

            if (Application.Current.Properties.ContainsKey("History") && Application.Current.Properties["History"] is string)
            {
                history.Text = Application.Current.Properties["History"] as string;
            }

            Content = new StackLayout {
				Children = {
					new Label { Text = "Tidigare slag", FontSize = Device.GetNamedSize (NamedSize.Large, typeof(Label))},
                    history
				}
			};
		}

	    public void AddDiceRoll(string diceRoll)
	    {
            Device.BeginInvokeOnMainThread(() =>
	        {
	            history.Text = "[" + DateTime.Now.ToString("HH:mm:ss") + "]: " + diceRoll + System.Environment.NewLine + history.Text;
                Application.Current.Properties["History"] = history.Text;
	        });
	    }

	}
}
